<template>
  <div :class="[selected && selected.id === id ? 'drag-selected' : '', 'row-outline']">
    <slot></slot>

    <template v-if="selected && selected.id === id">
      <div class="btn-drag">
        <div class="btn-drag-icon">
          <icon-drag-arrow />
          {{ itemConfig.name }}
        </div>
      </div>

      <div class="btn-group">
        <a-button-group type="primary" status="normal">
          <a-button size="small">
            <template #icon>
              <icon-heart-fill />
            </template>
          </a-button>
          <a-button size="small" @click.stop="copyItem">
            <template #icon>
              <icon-copy />
            </template>
          </a-button>
          <a-button size="small" @click.stop="deleteItem">
            <template #icon>
              <icon-delete />
            </template>
          </a-button>
        </a-button-group>
      </div>
    </template>
  </div>
</template>

<script lang="ts" setup>
import { inject, defineProps, defineEmits } from 'vue';

const props = defineProps({
  id: {
    type: String,
    default: () => ''
  },
  item: {
    type: Object,
    default: () => {
    }
  },
  itemConfig: {
    type: Object,
    default: () => {
    }
  }
});

const emits = defineEmits(['deleteItem', 'copyItem']);

const selected = inject('selected');

const deleteItem = () => {
  emits('deleteItem', props.item);
};

const copyItem = () => {
  emits('copyItem', props.item);
};
</script>

<script lang="ts">
export default {
  name: 'GridContainer'
};
</script>

<style lang="less" scoped>
@import "common-container";

.row-outline {
  position: relative;
  margin: 10px 0;
  padding: 10px 0;
  outline: 1px dashed #0967cc;
}
</style>